import { request } from "@/utils/service"
import type * as Type from "@/api/items/types/types"

const baseUrl = "catalog/"
export function getAllItemDataApi(productId: string) {
  return request<Type.itemData[]>({
    url: baseUrl + `getItemsByProductId/${productId}`,
    method: "get"
  })
}
export function getProductDataApi(categoryId: string) {
  return request<Type.productData[]>({
    url: baseUrl + `getProductsByCategoryId/${categoryId}`,
    method: "get"
  })
}
export function getItemDataApi(itemId: string) {
  return request<Type.itemData>({
    url: baseUrl + `getItemByItemId/${itemId}`,
    method: "get"
  })
}

export function getCartDataApi(userId: string) {
  return request<Type.cartData>({
    url: `cart/${userId}`,
    method: "get"
  })
}

export function addToCartDataApi(data: Type.addCartData) {
  return request({
    url: "addToCart",
    method: "post",
    data
  })
}

export function getAllProductApi() {
  return request<Type.productData[]>({
    url: baseUrl + "getAllProducts",
    method: "get"
  })
}

export function getAllItemApi() {
  return request<Type.itemData[]>({
    url: baseUrl + "getAllItems",
    method: "get"
  })
}

export function updateCartDataApi(data: Type.updateCartData) {
  return request({
    url: "cart",
    method: "put",
    data
  })
}

export function getCommentApi(itemId: string) {
  return request<Type.commentData[]>({
    url: baseUrl + `comment/${itemId}`,
    method: "get"
  })
}

export function addCommentApi(data: Type.requestCommentData) {
  return request({
    url: "comment",
    method: "post",
    data
  })
}

export function newOrderApi(data: Type.postItemData[]) {
  return request<Type.orderResponseData>({
    url: "newOrder",
    method: "post",
    data
  })
}

export function updateOrderApi() {
  return request({
    url: "order",
    method: "post"
  })
}

export function confirmOrderApi() {
  return request({
    url: "confirm",
    method: "post"
  })
}
export function getOrdersByUsernameApi(userId: string) {
  return request({
    url: `orders/${userId}`,
    method: "get"
  })
}

export function getOrderDetailApi(orderId: string) {
  return request({
    url: `orderDetail/${orderId}`,
    method: "get"
  })
}
